﻿using System;
using System.Collections.Generic;
using System.IO;

namespace InnovTech.Util
{
    public static class FileUtil
    {
        public static List<string> GetFiles(DirectoryInfo dir, Predicate<string> predicate)
        {
            List<string> result = new List<string>();
            foreach(var file in dir.GetFiles())
            {
                if (predicate(file.FullName))
                    result.Add(file.FullName);
            }
            foreach (var subDir in dir.GetDirectories())
            {
                result.AddRange(GetFiles(subDir, predicate));
            }
            return result;
        }

        public static List<string> GetFiles(string dir, Predicate<string> predicate)
        {
            Ensure.DirectoryExists(dir);
            DirectoryInfo dirInfo = new DirectoryInfo(dir);
            return GetFiles(dirInfo, predicate);
        }
    }
}
